package helper.base.math

import helper.base.A2Tuple
import kotlin.math.ceil
import kotlin.math.floor

object IntRangeHelper {
    fun getMinMaxIntPair(
        c1: Boolean,
        d1: Double,
        d2: Double,
        c2: Boolean,
    ): A2Tuple<Int, Int> {
        var min = ceil(d1)
        var max = floor(d2)
        if (!c1 && min == d1) {
            min += 1
        }
        if (!c2 && max == d2) {
            max -= 1
        }
        return A2Tuple(
            min.toInt(),
            max.toInt(),
        )
    }

    fun A2Tuple<Int, Int>.toIntRange(
    ): IntRange {
        return first..second
    }
}